var DAO=require('./DAO')
var shopDAO={
    //获取一个用户的购物车信息
    getShopList:function(userId,callback){
        DAO('select shopId,productName,productPic,product.productId,Addtime,count,price from shop,product where product.productId=shop.productId and userId=?',[userId],function(err,results){
            if(err){
                callback(err,null)
            }else{
                callback(null,results)
            }
        })
    },
    //增加商品进购物车
    addProduct:function(shop,callback){
         DAO('insert into shop(productId,userId,Addtime,count) value(?,?,now(),1)  ',[shop.productId,shop.userId],function(err,results){
             if(err){
                 callback(err,null)
             }else{
                 callback(null,results)
             }
         })
    },
    //通过用商品Id获取商品id，用来判断某商品是否加入了购物车
    getProductId:function(productId,callback){
        DAO('select productId from shop where productId=?',[productId],function(err,results){
            if(err){
                callback(err,null)
            }else{
                callback(null,results)
            }
        })
    },
    //删除一行或多个购物车
    delProduct:function(shopIds,callback){
        //用if语句判断？
         DAO('delete from shop where shopId in(?)',[shopIds],function(err,results){
             if(err){
                 callback(err,null)
             }else{
                 callback(null,results)
             }
         })
    },
    updateProductNum:function(shop,callback){
        DAO('update shop set count=? where shopId=?',[shop.count,shop.shopId],function(err,results){
            if(err){
                callback(err,null)
            }else{
                callback(null,results)
            }
        })
    }
}

module.exports=shopDAO